# 小票信息
order_number = "DH202311010001"
time_str = "2023-11-01 20:56:15"

# 商品列表
import datetime

# 商品列表
products = [
    {"name": "金士顿U盘8G", "quantity": 1, "unit_price": 40.00, "amount": 40.00},
    {"name": "胜创16GTF卡", "quantity": 1, "unit_price": 50.00, "amount": 50.00},
    {"name": "读卡器", "quantity": 1, "unit_price": 8.00, "amount": 8.00},
    {"name": "网线2米", "quantity": 1, "unit_price": 5.00, "amount": 5.00},
    {"name": "雷电将军", "quantity": 1, "unit_price": 500.00, "amount": 500.00},
]

# 补充缺失的变量
order_number = "SC20231025001"  # 小票单号
current_time = datetime.datetime.now()
time_str = current_time.strftime("%Y-%m-%d %H:%M:%S")  # 交易时间

# 计算总数和总额
total_count = len(products)
total_amount = sum(product["amount"] for product in products)

# 折扣设置（4折）
discount_rate = 0.4  # 折扣率
discount_percent = discount_rate * 10  # 转换为几折
discount_amount = total_amount * discount_rate  # 折扣金额
discounted_total = total_amount - discount_amount  # 折后总额

# 支付和找零
paid = 600
change = paid - discounted_total

# 打印小票
print("-" * 40)
print(f"单号: {order_number}")
print(f"时间: {time_str}")
print("-" * 40)
print(f"{'名称':<15}{'数量':<8}{'单价':<8}{'金额':<8}")
print("-" * 40)
for product in products:
    print(f"{product['name']:<15}{product['quantity']:<8}{product['unit_price']:<8.2f}{product['amount']:<8.2f}")
print("-" * 40)
print(f"总数: {total_count}")
print(f"总额: {total_amount:.2f}元")
print(f"折扣: {discount_percent}折")  # 显示为几折
print(f"折扣金额: {discount_amount:.2f}元")
print(f"折后总额: {discounted_total:.2f}元")
print(f"实收: {paid:.2f}元")
print(f"找零: {change:.2f}元")
print("-" * 40)

